
#--------------------------------------------------------------
# opbasm m4 语法：http://kevinpt.github.io/opbasm/rst/m4.html
# m4 是一个语法预编译器，能够生成PSM的汇编
#--------------------------------------------------------------

default:soft_m4_pid 


# 安装汇编工具链
toolchain:
	@rm -rf opbasm 
	@git clone https://gitee.com/yuan_hp/opbasm.git
	@cd opbasm && python3 setup.py install 
	@rm -rf opbasm 






# 仿真 m4/psm 程序 
soft_%:
	mkdir -p build 
	cd build && opbasm --m4 -3 ../soft/$@.psm 
	cd build && cp $@.mem firmware.hex  && sed -i '1d' firmware.hex 
	iverilog -o build/tb.vvp  -y ./rtl tb.v  
	@echo " --- sim ---"
	cd build && vvp tb.vvp 
	@echo " -----------"
	-cd build && grep -A3 "Actual memory size" $@.log

help:
	@echo "------------------------------------------------------------------------------------"
	@echo "make toolchain       install  toolchain for psm "
	@echo "make soft_*          compare  ./soft/soft_*.psm and sim"
	@echo "make psm_*           compare  ./psm/psm_*  and sim"
	@echo "make cpsm_*          compare  ./cpsm/cpsm_*  and sim, based on sdcc for pblaze"
	@echo "Note:"
	@echo "opbasm m4 语法      : http://kevinpt.github.io/opbasm/rst/m4.html"
	@echo "------------------------------------------------------------------------------------"



# 编译fchai环境
chai:
	@rm -rf fchai 
	@git clone https://gitee.com/yuan_hp/fchai.git
	@cd fchai && xmake 

.PHONY:test
test:
	bash test/test.sh
	

clean:
	@rm -rf build
	@rm -rf *.vcd *.vvp

include Project.mk 


